//
//  XJWalletChargeCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/23.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJWalletChargeCell.h"

@interface XJWalletChargeInputMoneyCell() <UITextFieldDelegate>
@property(nonatomic, strong) UILabel *rmbSymbolLabel; //人民币符号label
@property(nonatomic, strong) UITextField *moneyTextField; // 输入的金额
@property(nonatomic, strong) UIView *lineView; // 灰色的线条

@end
@implementation XJWalletChargeInputMoneyCell
#pragma mark - 一 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    
    return self;
}

- (void)setupView {
    [self.contentView addSubview:self.rmbSymbolLabel];
    [self.contentView addSubview:self.moneyTextField];
    [self.contentView addSubview:self.lineView];
}

#pragma mark - 二 lazy
// 就是一个人民币符号.￥
- (UILabel *)rmbSymbolLabel {
    if (!_rmbSymbolLabel) {
        _rmbSymbolLabel = [[UILabel alloc] init];
        _rmbSymbolLabel.text = @"￥";
        _rmbSymbolLabel.font = XJFONTSET_M(14);
    }
    return _rmbSymbolLabel;
}

- (UITextField *)moneyTextField {
    if (!_moneyTextField) {
        _moneyTextField = [[UITextField alloc] init];
        _moneyTextField.placeholder = @"请输入充值金额";
        _moneyTextField.font = XJFONTSET_M(20);
        _moneyTextField.delegate = self;
        
        _moneyTextField.keyboardType = UIKeyboardTypeNumberPad ;
    }
    return _moneyTextField;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = XJCOLOR_RGB(110, 110, 110);
    }
    return _lineView;
}

#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat kMargin = 15;
    CGFloat kMargin2 = 2;
    [self.rmbSymbolLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(kMargin);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-kMargin2);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    
    [self.moneyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(50);
        make.bottom.equalTo(self.lineView.mas_top);
        make.size.mas_equalTo(CGSizeMake(150, 40));
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.moneyTextField.mas_left);
        make.bottom.equalTo(self.contentView.mas_bottom);
        make.right.equalTo(self.contentView.mas_right);
        make.height.mas_equalTo(@0.5);
    }];
}
#pragma mark - 四 事件回调
//- (void)textFieldDidEndEditing:(UITextField *)textField {
//
//    if (self.walletChargeInputMoneyCellBlock) {
//        self.walletChargeInputMoneyCellBlock(textField.text);
//    }
//}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    if (self.walletChargeInputMoneyCellBlock) {
        self.walletChargeInputMoneyCellBlock(textField.text);
    }
    
    return YES;
}



@end

@interface XJWalletChargeCell()
@property(nonatomic, strong) UIImageView *iconIv;
@property(nonatomic, strong) UILabel *payTypeLable; //支付方式(支付宝支付、微信支付)
@property(nonatomic, strong) UIButton *selectButton;// 选择button

@end

@implementation XJWalletChargeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 一 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView{
    
    [self.contentView addSubview:self.iconIv];
    [self.contentView addSubview:self.payTypeLable];
    [self.contentView addSubview:self.selectButton];
}
#pragma mark - 二 lazy
- (UIImageView *)iconIv {
    if (!_iconIv) {
        _iconIv = [[UIImageView alloc] init];
    }
    return _iconIv;
}
- (UILabel *)payTypeLable {
    if (!_payTypeLable) {
        _payTypeLable = [[UILabel alloc] init];
        _payTypeLable.font = XJFONTSET_R(14.0);
    }
    return _payTypeLable;
}

- (UIButton *)selectButton {
    if (!_selectButton) {
        _selectButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_selectButton setImage:[UIImage imageNamed:@"selected_off"] forState:(UIControlStateNormal)];
        [_selectButton setImage:[UIImage imageNamed:@"selected_on"] forState:(UIControlStateSelected)];
        [_selectButton addTarget:self action:@selector(selectButtonAction) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _selectButton;
}


#pragma mark - 三 layout
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGFloat kMargin = 15;
    [self.iconIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kMargin);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    
    [self.payTypeLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconIv.mas_right).offset(kMargin);
        make.centerY.equalTo(self.contentView.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(150, 30));
        make.right.equalTo(self.selectButton.mas_left).offset(-10);
    }];
    
    [self.selectButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.mas_right).offset(-kMargin);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
}


- (void)selectButtonAction{
    XJLog(@"选择支付方式");
//    self.selectButton.selected = !self.selectButton.isSelected;
//    if (self.selectChargeTypeButtonBlock) {
//        self.selectChargeTypeButtonBlock();
//    }
}

- (void)configureWalletChargeCellWithIcon:(NSString *)icon payTypeStr:(NSString *)str isSelected:(BOOL)isSelected {
    self.iconIv.image = [UIImage imageNamed:icon];
    self.payTypeLable.text = str;
    self.selectButton.selected = isSelected;
}




@end
